//
//  APBottomMenuView.m
//  AqualPolo
//
//  Created by dong on 2024/5/6.
//

#import "APBottomMenuView.h"



@implementation APBottomMenuView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelButton.layer.cornerRadius = 8;
        _cancelButton.backgroundColor = LYRGBColor(87, 61, 255);
        _cancelButton.layer.masksToBounds = true;
        [_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
        _cancelButton.titleLabel.font = [LYFont fontWithSize:16 fontName:LYFontNamepfm];
        [self addSubview:_cancelButton];
        [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-20);
            make.size.mas_equalTo(CGSizeMake(183, 44));
            make.centerX.equalTo(self);
        }];
        
        _reportItem = [[APBottomMenuItem alloc] init];
        _reportItem.index = 2;
        [_reportItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _reportItem.titleLabel.text = @"Report";
        [self addSubview:_reportItem];
        [_reportItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_cancelButton.mas_top).offset(-30);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
        }];
        
        _blockItem = [[APBottomMenuItem alloc] init];
        [_blockItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _blockItem.index = 1;
        _blockItem.titleLabel.text = @"Block";
        [self addSubview:_blockItem];
        [_blockItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_reportItem.mas_top);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
        }];
        
        _followItem = [[APBottomMenuItem alloc] init];
        [_followItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _followItem.index = 0;
        _followItem.titleLabel.text = @"Follow";
        [self addSubview:_followItem];
        [_followItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_blockItem.mas_top);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
            make.top.equalTo(self);
        }];
        
        
    }
    return self;
}

- (void)itemDidClick:(APBottomMenuItem *)item{
    if ([self.delegate respondsToSelector:@selector(menuViewDidClickItem:)]) {
        [self.delegate menuViewDidClickItem:item.index];
    }
}

- (void)safeAreaInsetsDidChange{
    [super safeAreaInsets];
    [_cancelButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-(20 + self.safeAreaInsets.bottom));
    }];
}

@end

@implementation APBottomReportMenuView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _cancelButton.layer.cornerRadius = 8;
        _cancelButton.backgroundColor = LYRGBColor(87, 61, 255);
        _cancelButton.layer.masksToBounds = true;
        [_cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
        _cancelButton.titleLabel.font = [LYFont fontWithSize:16 fontName:LYFontNamepfm];
        [self addSubview:_cancelButton];
        [_cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self).offset(-20);
            make.size.mas_equalTo(CGSizeMake(183, 44));
            make.centerX.equalTo(self);
        }];
        
        _otherItem = [[APBottomMenuItem alloc] init];
        _otherItem.index = 4;
        [_otherItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _otherItem.titleLabel.text = @"Other";
        [self addSubview:_otherItem];
        [_otherItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_cancelButton.mas_top).offset(-30);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
        }];
        
        _politicalSensitiveItem = [[APBottomMenuItem alloc] init];
        [_politicalSensitiveItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _politicalSensitiveItem.index = 3;
        _politicalSensitiveItem.titleLabel.text = @"Political sensitive";
        [self addSubview:_politicalSensitiveItem];
        [_politicalSensitiveItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_otherItem.mas_top);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
        }];
        
        _fraudItem = [[APBottomMenuItem alloc] init];
        [_fraudItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _fraudItem.index = 2;
        _fraudItem.titleLabel.text = @"Fraud";
        [self addSubview:_fraudItem];
        [_fraudItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_politicalSensitiveItem.mas_top);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
        }];
        
        _falseGenderItem = [[APBottomMenuItem alloc] init];
        [_falseGenderItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _falseGenderItem.index = 1;
        _falseGenderItem.titleLabel.text = @"False gender";
        [self addSubview:_falseGenderItem];
        [_falseGenderItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_fraudItem.mas_top);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
        }];
        
        _pornographicItem = [[APBottomMenuItem alloc] init];
        [_pornographicItem addTarget:self action:@selector(itemDidClick:) forControlEvents:UIControlEventTouchUpInside];
        _pornographicItem.index = 0;
        _pornographicItem.titleLabel.text = @"Pornographic";
        [self addSubview:_pornographicItem];
        [_pornographicItem mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_falseGenderItem.mas_top);
            make.height.mas_equalTo(56);
            make.left.right.equalTo(self);
            make.top.equalTo(self);
        }];
    }
    return self;
}

- (void)itemDidClick:(APBottomMenuItem *)item{
    if ([self.delegate respondsToSelector:@selector(reportMenuViewDidClickItem:)]) {
        [self.delegate reportMenuViewDidClickItem:item.index];
    }
}

@end


@implementation APBottomMenuItem

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = LYRGBColor(20, 34, 32);
        _titleLabel.font = [LYFont fontWithSize:16 fontName:LYFontNamepfr];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        UIView *line = [[UIView alloc]init];
        line.backgroundColor = LYRGBColor(200, 202, 205);
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(20);
            make.right.equalTo(self).offset(-20);
            make.height.mas_equalTo(0.5);
            make.bottom.equalTo(self);
        }];
    }
    return self;
}



@end
